home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-5625
/
3d2-_pov.12
/
source.c
/
cyb_pov.ruf
< prev
Wrap
Text File
|
1995-10-15
|
10KB
|
255 lines
/*
Converts\ed Cybersculpt 3D2-Files in the POV-Sourceformat.
(c) June 1994 Jochen Knaus
Nickeleshalde 19
88400 Biberach
07351 / 24483
date: 27.7.1994
Update: 30.9.1994
version: 1.20
This Konvertierprogramm is Freeware, in the spirits of the POV.
Somewhen soon will(_be)'s to "smooth triangles" extends\ed.
opposite versions <=1.01 became the Kommandozeilenformat altered.
The Files take (self) now too with POV 2.X (over option "-v2").
It can now too a "bounded_by" optimisation become generates\d.
From version 1.2: Faster and small(er)...
call: CYB_POV -s<source> -d<destin> -n<objektnamen> -v<povversion>
-b<mode>
*/
#include<tos.H>
#include<stdio.H>
#include<string.H>
#include<portab.H>
#include<stdlib.H>
#include<limits.H>
#define VERSION_A 1
#define VERSION_B 2
#define PATHLEN 256+1
int abbruch( void );
/* Filehandles global... */
int source, destin;
int main( int argc, char *argv[] )
{
WORD header[128], anz_obj, anz_dot, anz_facetten,
*dot, *facetten;
char obj_name[10], buffer[2560], buffer2[256],
buffer3[4] = { '}', 13, 10, 0 },
def_file[PATHLEN] = "STD.POV", def_name[64] = "DEFOBJ",
source_file[PATHLEN], minus[2] = { '-', 0 }, nullos[2] = { 0 },
*vorzeichen[6];
register int i, j, m;
int pov_mode = 1, bounds = 0; /* POV-version. */
int wandel[6], minmax[6];
puts( "" );
printf( "3D2->POV Converter vers. %d.%d, (c) 1994 by Jochen Knaus (AURA), Freeware.\n",
VERSION_A, VERSION_B );
puts( "" );
if( argc <= 1 ) return( -1 ); /* No parameter(s) ? */
for( i=1, source_file[0] = '\0' ; i < argc ; i++ )
{
if( (argv[i])[0] == '-' ) /* parameter(s) ? */
{
switch( (argv[i])[1] )
{
/* Zielfile ? */
case 'd': strncpy( def_file, argv[i]+2, 127 ); break;
/* object names ? */
case 'n': strncpy( def_name, argv[i]+2, 63 ); break;
/* Sourcefile ? */
case 's': strncpy( source_file, argv[i]+2, 127 ); break;
/* POV-version ? */
case 'v': pov_mode = (int) ((argv[i])[2] -'0'); break;
/* Grenzbox calculate. */
case 'b': bounds = (int) ((argv[i])[2] -'0') ; break;
}
}
}
if( strlen( source_file ) == 0 ) /* No 3D2-File given ? */
{ puts( "No source (3D2) file." );
return( -1 ); }
/* source file open. */
if( ( source = Fopen( source_file, FO_READ ) ) < 0 )
{ puts( "Cannot open sourcefile. ");
return( source ); }
/* destination file generate. */
if( ( destin = Fcreate( def_file, (int) 0 ) ) < 0 )
{ puts( "Cannot create destinationfile." );
return( destin ); }
/* Header read. */
if( Fread( source, (long) 256, header ) < 0 ) return( abbruch() );
if( header[0] != 15618 ) /* 3D2-File ? */
{ puts( "No 3D2 File..." );
return( abbruch() ); }
anz_obj = header[1];
printf( "%s: Convert %d object(s).\n\n", source_file, anz_obj );
sprintf( buffer, "#declare %s = union {%s", def_name, &buffer3[1] );
Fwrite( destin, strlen(buffer), buffer );
if( bounds != 0 ) /* Grenzwerte initialise. */
{
minmax[0] = INT_MAX; minmax[1] = INT_MIN;
minmax[2] = INT_MAX; minmax[3] = INT_MIN;
minmax[4] = INT_MAX; minmax[5] = INT_MIN;
}
for( i=0 ; i<anz_obj ; i++ ) /* All objects ! */
{
Fread( source, (long) 9, obj_name ); /* object names */
Fread( source, (long) 2, &anz_dot );
if( anz_dot > 0 )
{
/* memory for points reserve. */
if( ( dot = malloc( (long) (anz_dot * 6) ) ) == NULL )
return( abbruch() );
else
Fread( source, (long) anz_dot*3*2, dot ); /* points read in. */
if( bounds != 0 ) /* object borders secure ? */
{
for( j = 0 ; j < anz_dot ; j++ ) /* Objektextremas festellen. */
{
if( dot[j*3+0] < minmax[0] ) minmax[0] = dot[j*3+0];
if( dot[j*3+0] > minmax[1] ) minmax[1] = dot[j*3+0];
if( dot[j*3+1] < minmax[2] ) minmax[2] = dot[j*3+1];
if( dot[j*3+1] > minmax[3] ) minmax[3] = dot[j*3+1];
if( dot[j*3+2] < minmax[4] ) minmax[4] = dot[j*3+2];
if( dot[j*3+2] > minmax[5] ) minmax[5] = dot[j*3+2];
}
}
/* number Facetten. */
Fread( source, (long) 2, &anz_facetten );
printf( "'%s' %d facettes: ", obj_name, anz_facetten );
/* memory for triangles. */
if( ( facetten = malloc( (long) (anz_facetten * 8) ) ) == NULL )
{ free( dot ); return( abbruch() ); }
else
/* Facetten read in. */
Fread( source, (long) anz_facetten*4*2, facetten );
/* Facetten convert. */
for( j = 0, buffer[0] = '\0' ; j<anz_facetten ; j++ )
{
strcat( buffer, " triangle{" );
/* points change... 2 places Nachkomma extend (/100), further
reduction must POV take (on)... */
for( m=0 ; m<3 ; m++ )
{
wandel[0] = (dot[facetten[j*4+m]*3+0]); /* x */
wandel[1] = (dot[facetten[j*4+m]*3+1]); /* y */
wandel[2] = (dot[facetten[j*4+m]*3+2]); /* z */
wandel[3] = abs( wandel[0] ); /* For Nachkomma... */
wandel[4] = abs( wandel[1] );
wandel[5] = abs( wandel[2] );
if( wandel[0] < 0 ) vorzeichen[0] = minus; else vorzeichen[0] = nullos;
if( wandel[1] < 0 ) vorzeichen[1] = minus; else vorzeichen[1] = nullos;
if( wandel[2] < 0 ) vorzeichen[2] = minus; else vorzeichen[2] = nullos;
if( pov_mode == 1 ) /* POV vers.1 : No comma */
sprintf( buffer2, "<%s%d.%d %s%d.%d %s%d.%d>",
vorzeichen[0], wandel[3] / 100, wandel[3] % 100,
vorzeichen[1], wandel[4] / 100, wandel[4] % 100,
vorzeichen[2], wandel[5] / 100, wandel[5] % 100 );
else
sprintf( buffer2, "<%s%d.%d,%s%d.%d,%s%d.%d>",
vorzeichen[0], wandel[3] / 100, wandel[3] % 100,
vorzeichen[1], wandel[4] / 100, wandel[4] % 100,
vorzeichen[2], wandel[5] / 100, wandel[5] % 100 );
strcat( buffer, buffer2 );
}
strcat( buffer, buffer3 );
if( j%10 == 0 ) /* All 10 triangles write. */
{
printf( "." );
Fwrite( destin, strlen(buffer), buffer );
buffer[0] = '\0';
}
}
if( strlen( buffer ) > 0 ) /* Restlichen points write. */
Fwrite( destin, strlen(buffer), buffer );
free(dot); free(facetten);
}
puts( " done." );
}
if( bounds != 0 ) /* <bounded_by> write. */
{
wandel[0] = abs( minmax[0] ); wandel[1] = abs( minmax[1] );
wandel[2] = abs( minmax[2] ); wandel[3] = abs( minmax[3] );
wandel[4] = abs( minmax[4] ); wandel[5] = abs( minmax[5] );
if( minmax[0] < 0 ) vorzeichen[0] = minus; else vorzeichen[0] = nullos;
if( minmax[1] < 0 ) vorzeichen[1] = minus; else vorzeichen[1] = nullos;
if( minmax[2] < 0 ) vorzeichen[2] = minus; else vorzeichen[2] = nullos;
if( minmax[3] < 0 ) vorzeichen[3] = minus; else vorzeichen[3] = nullos;
if( minmax[4] < 0 ) vorzeichen[4] = minus; else vorzeichen[4] = nullos;
if( minmax[5] < 0 ) vorzeichen[5] = minus; else vorzeichen[5] = nullos;
if( pov_mode == 1 )
sprintf( buffer, " bounded_by{box{<%s%d.%d %s%d.%d %s%d.%d><%s%d.%d %s%d.%d %s%d.%d>}}",
vorzeichen[0], wandel[0] / 100, wandel[0] % 100,
vorzeichen[2], wandel[2] / 100, wandel[2] % 100,
vorzeichen[4], wandel[4] / 100, wandel[4] % 100,
vorzeichen[1], wandel[1] / 100, wandel[1] % 100,
vorzeichen[3], wandel[3] / 100, wandel[3] % 100,
vorzeichen[5], wandel[5] / 100, wandel[5] % 100 );
else
sprintf( buffer, " bounded_by{box{<%s%d.%d,%s%d.%d,%s%d.%d><%s%d.%d,%s%d.%d,%s%d.%d>}}",
vorzeichen[0], wandel[0] / 100, wandel[0] % 100,
vorzeichen[2], wandel[2] / 100, wandel[2] % 100,
vorzeichen[4], wandel[4] / 100, wandel[4] % 100,
vorzeichen[1], wandel[1] / 100, wandel[1] % 100,
vorzeichen[3], wandel[3] / 100, wandel[3] % 100,
vorzeichen[5], wandel[5] / 100, wandel[5] % 100 );
Fwrite( destin, strlen( buffer ), buffer );
buffer[0] = 13; buffer[1] = 10; buffer[2] = '\0';
Fwrite( destin, 2, buffer );
}
Fwrite( destin, strlen(buffer3), buffer3 );
Fclose( source ); Fclose( destin );
return( 0 );
}
int abbruch()
{
Fclose( source );
Fclose( destin );
return( -1 ); /* Gemdosfehler: <0 */
}
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙
This word-by-word exchange from a German document, with some
adjustments for German idiom, was made with a registered version
of Ruftrade2.
∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙